{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">编辑作品分类</h3>
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray-2">上级分类ID</td>
			<td>
				<select name="pid" >
					<option value="0">作为顶级分类</option>
					{volist name=":set_recursion(get_book_cate())" id="v"}
					<option value="{$v.id}" {eq name="$detail.pid" value="$v.id" }selected{/eq}>{$v.title}</option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray-2">标题<font>*</font></td>
			<td><input type="text" name="name"  lay-verify="required" lay-reqText="请完善标题" value="{$detail.name}" autocomplete="off" placeholder="请输入标题" class="layui-input"></td>
			<td class="layui-td-gray-2">标识</td>
			<td><input type="text" name="key" value="{$detail.key}" autocomplete="off" placeholder="请输入标识" class="layui-input"></td>			
		</tr>
		<tr>
			<td class="layui-td-gray-2">排序</td>
			<td><input type="text" name="ordernum"  value="{$detail.ordernum}" autocomplete="off" placeholder="请输入排序（同级有效）" class="layui-input"></td>
			<td class="layui-td-gray-2">状态</td>
			<td>
				<input type="radio" name="status" value="0" title="禁止" {eq name="$detail.status" value="0"} checked{/eq}>
				<input type="radio" name="status" value="1" title="正常" {eq name="$detail.status" value="1"} checked{/eq}>
			</td><td colspan='2'></td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">描述</td>
			<td colspan="5"><input type="text" name="remark" value="{$detail.remark|default=''}" autocomplete="off" placeholder="请输入描述" class="layui-input"></td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">图标</td>
			<td colspan="5" style="vertical-align:top">
				<div class="layui-upload">
					<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_icons">选择上传图片</button>
					<div class="layui-upload-list" id="upload_box_icons">
						<img src="{notempty name="$detail.icons"}{$detail.icons}{/notempty}" onerror="javascript:this.src='{__ASSETS__}/init/images/nonepic600x360.jpg';this.onerror=null;" style="width:200px;max-width:200px" />
						<input type="hidden" name="icons" value="{notempty name="$detail.icons"}{$detail.icons}{/notempty}" >
					</div>
				</div>
			</td>
		</tr>
	</table>
	<div class="py-3">
		<input type="hidden" name="id" value="{$detail.id}"/>
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	var moduleInit = ['tool'];

	function feiniaoInit() {
		var form = layui.form, tool = layui.tool;
		
		//上传图标
		var upload_icons = layui.upload.render({
			elem: '#upload_btn_icons',
			url: '{:url("api/upload")}',
			done: function (res) {
				//如果上传失败
				if (res.code == 1) {
					return layer.msg('上传失败');
				}
				//上传成功
				$('#upload_box_icons input').attr('value', res.data.filepath);
				$('#upload_box_icons img').attr('src', res.data.filepath);
			}
		});
				
		//监听提交
		form.on('submit(webform)', function (data) {			
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					setTimeout(function () {
						parent.location.reload();
					}, 1000);
				}
			}
			tool.post("{:url('category/edit')}", data.field, callback);
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->